package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseCategory1;
import com.atguigu.gmall.product.entity.BaseCategory2;
import com.atguigu.gmall.product.entity.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: BaseCategory1Controller
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author ltystart
 * @Create 2025/8/15 11:17
 * @Version 1.0
 */
@Api(tags = "分类接口")
@RestController
public class BaseCategory1Controller {
    @Autowired
    private BaseCategory1Service baseCategory1Service;

    @Autowired
    private BaseCategory2Service baseCategory2Service;

    @Autowired
    private BaseCategory3Service baseCategory3Service;

    /**
     * 查询所有一级分类
     *
     * @return
     */
    @ApiOperation("查询所有一级分类")
    @GetMapping("/admin/product/getCategory1")
    public Result getAll() {
        List<BaseCategory1> list = baseCategory1Service.list();
        return Result.ok(list);
    }

    /**
     * 根据1级分类id，查找对应的2级分类id
     *
     * @param category1_id
     * @return
     */
    @ApiOperation("根据1级分类id，查找对应的2级分类id")
    @GetMapping("/admin/product/getCategory2/{category1_id}")
    public Result getCategory2(@PathVariable("category1_id") Long category1_id) {
        List<BaseCategory2> list = baseCategory2Service.getCategory2(category1_id);
        return Result.ok(list);
    }

    /**
     * 根据2级分类id，查找对应的3级分类id
     *
     * @param category2_id
     * @return
     */
    @ApiOperation("根据2级分类id，查找对应的3级分类id")
    @GetMapping("/admin/product/getCategory3/{category2_id}")
    public Result getCategory3(@PathVariable("category2_id") Long category2_id) {
        List<BaseCategory3> list = baseCategory3Service.getCategory3(category2_id);
        return Result.ok(list);
    }
}
